package com.hhh.bigevent.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hhh.bigevent.anno.State;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.Default;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.URL;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 *
 * </p>
 *
 * @author hehehe
 * @since 2025-04-15
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@TableName("article")
@Accessors(chain = true)
@ApiModel(value = "ArticleDO对象", description = "")
public class ArticleDO extends Model<ArticleDO> {

    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @NotNull(message = "id不能为空", groups = Update.class)
    @ApiModelProperty("ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 文章标题
     */
    @NotEmpty(message = "文章标题不能为空")
    @TableField("title")
    @ApiModelProperty("文章标题")
    private String title;

    /**
     * 文章内容
     */
    @NotEmpty(message = "文章内容不能为空")
    @TableField("content")
    @ApiModelProperty("文章内容")
    private String content;

    /**
     * 文章封面
     */
    @URL(message = "需要是一个合法的URL")
    @NotEmpty(message = "文章封面不能为空")
    @TableField("cover_img")
    @ApiModelProperty("文章封面")
    private String coverImg;

    /**
     * 文章状态: 只能是[已发布] 或者 [草稿]
     */
    @State
    @TableField("state")
    @ApiModelProperty("文章状态: 只能是[已发布] 或者 [草稿]")
    private String state;

    /**
     * 文章分类ID
     */
    @NotNull(message = "文章分类ID不能为空")
    @TableField("category_id")
    @ApiModelProperty("文章分类ID")
    private Integer categoryId;

    /**
     * 创建人ID
     */
    @JsonIgnore
    @ApiModelProperty("创建人ID")
    @TableField("create_user")
    private Integer createUser;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("创建时间")
    @TableField("create_time")
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("修改时间")
    @TableField("update_time")
    private LocalDateTime updateTime;

    public static final String ID = "id";

    public static final String TITLE = "title";

    public static final String CONTENT = "content";

    public static final String COVER_IMG = "cover_img";

    public static final String STATE = "state";

    public static final String CATEGORY_ID = "category_id";

    public static final String CREATE_USER = "create_user";

    public static final String CREATE_TIME = "create_time";

    public static final String UPDATE_TIME = "update_time";

    @Override
    public Serializable pkVal() {
        return this.id;
    }

    public interface Update extends Default {
    }
}
